package org.seckill.service;

import org.seckill.mapper.SuccessKilledMapper;
import org.seckill.model.SuccessKilled;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

/**
 * @author Wrb
 * @date 2019/7/3 15:28
 */
@Service
public class SuccessKilledService {

	@Autowired
	private SuccessKilledMapper successKilledMapper;

	public int insertSuccessKilled(SuccessKilled successKilled) {
		int ret;
		try {
			//主键冲突
			ret = successKilledMapper.insertSelective(successKilled);
		} catch (DuplicateKeyException e) {
			ret = 0;
		}
		return ret;
	}

	public SuccessKilled selectSuccessKilledByKey(Long seckillId, Long userPhone) {
		return successKilledMapper.selectByPrimaryKey(seckillId, userPhone);
	}
}